﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SAPbouiCOM;
using SAPbobsCOM;

namespace BoAddonBiz_FreightForwarder
{
    class B1Form_CustomsCargo : SAPBoAddon.B1Form
    {
        //string FORM_NOTNULLABLE;

        protected override bool BeforeSaveCheckFormData()
        {
            #region 保存前自动流水Code
            Recordset rs = this.SBOCompany.GetBusinessObject(BoObjectTypes.BoRecordset);
            rs.DoQuery("select isnull(max(Code),0) as MAX from [@AVA_FF_OCUC]");
            int max = 1;
            if (rs.Fields.Item("MAX").Value.ToString().Trim().Length > 0)
            {
                max = Convert.ToInt32(rs.Fields.Item("MAX").Value.ToString().Trim()) + 1;
            }
            this.CurrentForm.DataSources.DBDataSources.Item("@AVA_FF_OCUC").SetValue("Code", 0, max.ToString());
            #endregion

            //判断物料编码是否为空 
            if (this.IsItemCodeNull())
            {
                ShowMessageInformation("222");
                return false;
            }
            //判断物料名称是否为空
            if (this.IsItemNameNull())
            {
                ShowMessageInformation("6");
                return false;
            }
            //判断英文品名是否为空
            if (this.IsItemEnlishNameNull())
            {
                ShowMessageInformation("8");
                return false;
            }
            //判断监管条件是否为空
            if (this.IsConditionNull())
            {
                ShowMessageInformation("16");
                return false;
            }
            //判断申报要素是否为空
            if (this.IsFactorNull())
            {
                ShowMessageInformation("18");
                return false;
            }
            //判断单据是否为空
            if (this.IsDocEntryNull())
            {
                ShowMessageInformation("22");
                return false;
            }
            return true;
            #region 注释
            //KeyValuePair<string, string> uid_description;
            //bool check = Utils.CheckFormNullable(this.CurrentForm, FORM_NOTNULLABLE, out uid_description);
            //if (!check)
            //{
            //    SBOApp.SetStatusBarMessage(String.Format(B1ResourceManager.GetInstance().GetMessageFormat(this, SBOApp.Language, "CanNotBeNull"), uid_description.Value), SAPbouiCOM.BoMessageTime.bmt_Short, true);
            //    this.CurrentForm.Items.Item(uid_description.Key).Click(BoCellClickType.ct_Regular);
            //}
            //return check;
            #endregion
        }
        public B1Form_CustomsCargo()
        {
            frm_ItemEvent += new SAPBoAddon.IB1FormEvents.B1ItemEventEventHandler(B1Form_CustomsCargo_frm_ItemEvent);
        }
        //Item 事件
        void B1Form_CustomsCargo_frm_ItemEvent(SAPBoAddon.B1AddonBase.B1ItemEvent pVal, ref bool BubbleEvent)
        {

        }
        protected override void FormEditModeChange(SAPBoAddon.frmItemEditMode frmEditMode)
        {

        }
        protected override void FormInfoSetting(SAPBoAddon.B1FormSetting FormSetting)
        {
            FormSetting.FormType = B1FormTypes.ado_AVA_FF_CustomsCargo;
            FormSetting.FormFileName = B1FormTypes.ado_AVA_FF_CustomsCargo.ToString() + "Form.srf";
        }
        protected override void InitializeForm(SAPBoAddon.B1FormInitializePar InitPar)
        {

        }
        /// <summary>
        /// 显示中文信息还是英文提示信息
        /// </summary>
        /// <param name="UItemId"></param>
        private void ShowMessageInformation(string UItemId)
        {
            SAPbouiCOM.Form oFrom;
            oFrom = this.CurrentForm;
            string information = SAPBoAddon.B1Assistant.Item.GetValue(oFrom, UItemId).ToString();
            if (SBOCompany.language.ToString().Trim().Contains("Chinese"))
                SBOApp.StatusBar.SetText(information + "不能为空！", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Warning);
            else
                SBOApp.StatusBar.SetText(information + " IS NOT NULL！", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Warning);
        }
        /// <summary>
        /// 判断物料编码是否为空 
        /// </summary>
        /// <returns></returns>
        private bool IsItemCodeNull()
        {
            bool RetVal = false;
            SAPbouiCOM.Form oForm;
            oForm = this.CurrentForm;
            string ItemCode = SAPBoAddon.B1Assistant.Item.GetValue(oForm, "111").ToString();
            if (ItemCode.Trim().Length == 0)
            {
                RetVal = true;
            }
            return RetVal;

        }
        /// <summary>
        /// 判断物料名称是否为空
        /// </summary>
        /// <returns></returns>
        private bool IsItemNameNull()
        {
            bool RetVal = false;
            SAPbouiCOM.Form oForm;
            oForm = this.CurrentForm;
            string ItemName = SAPBoAddon.B1Assistant.Item.GetValue(oForm, "5").ToString();
            if (ItemName.Trim().Length == 0)
            {
                RetVal = true;
            }
            return RetVal;

        }
        /// <summary>
        /// 判断监管条件是否为空
        /// </summary>
        /// <returns></returns>
        private bool IsConditionNull()
        {
            bool RetVal = false;
            SAPbouiCOM.Form oForm;
            oForm = this.CurrentForm;
            string Condition = SAPBoAddon.B1Assistant.Item.GetValue(oForm, "1000004").ToString();
            if (Condition.Trim().Length == 0)
            {
                RetVal = true;
            }
            return RetVal;
        }
        /// <summary>
        /// 判断英文品名是否为空
        /// </summary>
        /// <returns></returns>
        private bool IsItemEnlishNameNull()
        {
            bool RetVal = false;
            SAPbouiCOM.Form oForm;
            oForm = this.CurrentForm;
            string ItemEnlishName = SAPBoAddon.B1Assistant.Item.GetValue(oForm, "7").ToString();
            if (ItemEnlishName.Trim().Length == 0)
            {
                RetVal = true;
            }
            return RetVal;
        }
        /// <summary>
        /// 判断申报要素是否为空
        /// </summary>
        /// <returns></returns>
        private bool IsFactorNull()
        {
            bool RetVal = false;
            SAPbouiCOM.Form oForm;
            oForm = this.CurrentForm;
            string Factor = SAPBoAddon.B1Assistant.Item.GetValue(oForm, "1000005").ToString();
            if (Factor.Trim().Length == 0)
            {
                RetVal = true;
            }
            return RetVal;

        }
        /// <summary>
        /// 判断备注是否为空
        /// </summary>
        /// <returns></returns>
        private bool IsRemarkNull()
        {
            bool RetVal = false;
            SAPbouiCOM.Form oForm;
            oForm = this.CurrentForm;
            string Remark = SAPBoAddon.B1Assistant.Item.GetValue(oForm, "1000007").ToString();
            if (Remark.Trim().Length == 0)
            {
                RetVal = true;
            }
            return RetVal;

        }
        /// <summary>
        /// 判断单据是否为空
        /// </summary>
        /// <returns></returns>
        private bool IsDocEntryNull()
        {
            bool RetVal = false;
            SAPbouiCOM.Form oForm;
            oForm = this.CurrentForm;
            string DocEntry = SAPBoAddon.B1Assistant.Item.GetValue(oForm, "21").ToString();
            if (DocEntry.Trim().Length == 0)
            {
                RetVal = true;
            }
            return RetVal;

        }
        /// <summary>
        /// 判断参考一是否为空
        /// </summary>
        /// <returns></returns>
        private bool IsReferenceResourcesOneNull()
        {
            bool RetVal = false;
            SAPbouiCOM.Form oForm;
            oForm = this.CurrentForm;
            string ReferenceResourcesOne = SAPBoAddon.B1Assistant.Item.GetValue(oForm, "1000001").ToString();
            if (ReferenceResourcesOne.Trim().Length == 0)
            {
                RetVal = true;
            }
            return RetVal;

        }
        /// <summary>
        /// 判断参考二是否为空
        /// </summary>
        /// <returns></returns>
        private bool IsReferenceResourcesTwoNull()
        {
            bool RetVal = false;
            SAPbouiCOM.Form oForm;
            oForm = this.CurrentForm;
            string ReferenceResourcesTwo = SAPBoAddon.B1Assistant.Item.GetValue(oForm, "9").ToString();
            if (ReferenceResourcesTwo.Trim().Length == 0)
            {
                RetVal = true;
            }
            return RetVal;

        }
    }
}
